//
//  HX_CustomCell.m
//  UI22-阿里星球（音乐）
//
//  Created by 韩旭 on 16/8/14.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "HX_CustomCell.h"
#import "HX_CollectionCustomCell.h"
#import "DataSmallModel.h"


@implementation HX_CustomCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatCollectionView];
    }
    return self;
}

- (void)setArrDataSource:(NSMutableArray *)arrDataSource {
    _arrDataSource = arrDataSource;
    
}
- (void)creatCollectionView {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.sectionInset = UIEdgeInsetsMake(0, 20, 0, 20);
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    [self.contentView addSubview:_collectionView];
    _collectionView.backgroundColor = [UIColor blackColor];
    [_collectionView registerNib:[UINib nibWithNibName:@"HX_CollectionCustomCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"reuse"];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _arrDataSource.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HX_CollectionCustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];

    cell.dataSmallModel = _arrDataSource[indexPath.row];
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake((self.contentView.bounds.size.width - 60) / 3, self.contentView.bounds.size.height);
}
- (void)layoutSubviews {
    [super layoutSubviews];
    self.collectionView.frame = CGRectMake(0, 0, kWidth, self.contentView.frame.size.height);
}


@end
